import { setSidebarOpen, getSidebarOpen ,getSidebarWidth,setSidebarWidth,getSize,setSize } from '../../utils/cookies.js'
//sidebar侧边栏是否打开
//device电脑还是移动
//size大小
const state = {
	collapsed: !!+getSidebarOpen() || false,
	width: getSidebarWidth()|| '80',
	size:getSize()||'xs'
}

const mutations = {
	TOGGLE_SIDEBAR: (state, boolean) => {
		state.collapsed = boolean
	},
	TOGGLE_WIDTH: (state, width) => {
		state.width = width
	},
	TOGGLE_SIZE:(state, size) => {
		state.size = size
	},
}

const actions = {
	toggleSideBar({ commit }, boolean) {
		console.log('boolean',boolean)
		commit('TOGGLE_SIDEBAR', boolean)
		if (boolean) {
			setSidebarOpen(1)
			console.log(!!+getSidebarOpen())
		} else {
			setSidebarOpen(0)
			console.log(!!+getSidebarOpen())
		}
	},
	toggleWidth({ commit }, width) {
		commit('TOGGLE_WIDTH', width)
	},
	toggleSize({ commit }, size) {
		commit('TOGGLE_SIZE', size)
	},
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
